var DailyBalanceStatistics = {};
DailyBalanceStatistics.contextpath = "";
DailyBalanceStatistics.initPage = function(contextpath) {
	DailyBalanceStatistics.contextpath = contextpath;

	layui.use(['table','form', 'laydate'], function() {
		 var laydate = layui.laydate;
		//日期
		  laydate.render({
		    elem: '#date',
		    type: 'month',
		    done: function(value, date, endDate){
				var date= value;
				DailyBalanceStatistics.reload(date);
				
		    	}
		  });
	});
}

DailyBalanceStatistics.reload=function(date){
	$.ajax({
		type : "POST",
		url : "/web2019/finance/ajaxQueryDailyBalanceStatistics.action",
		dataType : "json",
		data : {"date":date},
		beforeSend:function(){
			layer.load(1);
		},
		complete:function(){
			layer.close(layer.index);
		},
		success : function(data) {
			if (data.code == "0000") {
				DailyBalanceStatistics.getPayEcharts(data.payList);
				DailyBalanceStatistics.getIncomeEcharts(data.incomeList);
				$("#payNum").html(data.pay+"元");
				$("#incomeNum").html(data.income+"元");
			} else {
				layer.alert(data.message);
			}
		},
		error : function(data) {

		}
	});
}

DailyBalanceStatistics.getPayEcharts=function(list){
	var columns = [];
	var data=[];
	for(var i=0;i<list.length;i++){
		var obj={};
		obj.name=list[i].balanceTypeName;
		obj.value=list[i].money;
		columns.push(list[i].balanceTypeName);
		data.push(obj);
	}
	console.log(columns);
	console.log(data);
	var myChart = echarts.init(document.getElementById('pay'));
	var option = {};
	var app = {};
	app.title = '环形图';

	option = {
	    tooltip: {
	        trigger: 'item',
	        formatter: "{a} <br/>{b}: {c} ({d}%)"
	    },
	    legend: {
	        orient: 'vertical',
	        x: 'left',
	        data:columns
	    },
	    series: [
	        {
	            name:'当月开销',
	            type:'pie',
	            radius: ['50%', '70%'],
	            avoidLabelOverlap: false,
	            label: {
	                normal: {
	                    show: false,
	                    position: 'center'
	                },
	                emphasis: {
	                    show: true,
	                    textStyle: {
	                        fontSize: '30',
	                        fontWeight: 'bold'
	                    }
	                }
	            },
	            labelLine: {
	                normal: {
	                    show: false
	                }
	            },
	            data:data
	        }
	    ]
	};
	 myChart.setOption(option);
}

DailyBalanceStatistics.getIncomeEcharts=function(list){
	var columns = [];
	var data=[];
	for(var i=0;i<list.length;i++){
		var obj={};
		obj.name=list[i].balanceTypeName;
		obj.value=list[i].money;
		columns.push(list[i].balanceTypeName);
		data.push(obj);
	}
	console.log(columns);
	console.log(data);
	var myChart = echarts.init(document.getElementById('income'));
	var option = {};
	var app = {};
	app.title = '环形图';

	option = {
	    tooltip: {
	        trigger: 'item',
	        formatter: "{a} <br/>{b}: {c} ({d}%)"
	    },
	    legend: {
	        orient: 'vertical',
	        x: 'left',
	        data:columns
	    },
	    series: [
	        {
	            name:'当月收入',
	            type:'pie',
	            radius: ['50%', '70%'],
	            avoidLabelOverlap: false,
	            label: {
	                normal: {
	                    show: false,
	                    position: 'center'
	                },
	                emphasis: {
	                    show: true,
	                    textStyle: {
	                        fontSize: '30',
	                        fontWeight: 'bold'
	                    }
	                }
	            },
	            labelLine: {
	                normal: {
	                    show: false
	                }
	            },
	            data:data
	        }
	    ]
	};
	 myChart.setOption(option);
}
